/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package questionaire.resources;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import process.ProcessManager;

/**
 *
 * @author aqeel
 */
public class Questionaire extends javax.swing.JFrame implements KeyListener
{
    private static Map<Integer,String> questions = new LinkedHashMap<Integer,String>();
    private static Map<Integer, List> options = new LinkedHashMap<Integer,List>();
    public static Integer currentNo = 1;
    public static Integer questionClicked = 1;
    private static Map<Integer,List<Integer>> optionClicked = new LinkedHashMap<Integer,List<Integer>>();
    private static Map<Integer,Map> inferenceMap = new LinkedHashMap<Integer,Map>();
    private int minimumPrice = 0;
    private int maximumPrice = 10000000;
    public static ArrayList array = new ArrayList();
    ProcessAnswer processAnswer = new ProcessAnswer();
    ProcessManager processManager;
    /**
     * Creates new form Questionaire
     */
    public Questionaire()
    {
        revalidate();
        initComponents();
        init();
    }
    
    public void init()
    {
        revalidate();
        setBackground(Color.WHITE);
        getContentPane().setBackground(Color.WHITE);
        startPanel.setBackground(Color.WHITE);
        jLabel1.setFont(new Font(Font.SANS_SERIF,Font.BOLD,66));
        jLabel2.setFont(new Font(Font.SANS_SERIF,Font.BOLD,18));
        jButton1.setFont(new Font(Font.SANS_SERIF,Font.BOLD,18));
        jLabel3.setFont(new Font(Font.SANS_SERIF,Font.BOLD,30));
        jLabel3.setForeground(Color.GREEN);
        jButton1.setBackground(new Color(0,114,198));
        jButton2.setBackground(new Color(0,114,198));
        jButton3.setBackground(new Color(0,114,198));
        jButton3.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                rulesPanel.setVisible(true);
            }
        });
        jButton2.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                clearAll();
            }
        });
        jButton1.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                startPanel.setVisible(false);
                mainPanel.setVisible(true);
            }
        });
        jButton1.setForeground(Color.BLACK);
        mainPanel.setVisible(false);
        resultPanel.setVisible(false);
        resultPanel.setBackground(Color.WHITE);
        mainPanel.setBackground(Color.WHITE);
        bottomPanel.setBackground(Color.WHITE);
        optionPanel.setBackground(Color.WHITE);
        jLabel1.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 24));
        jLabel1.setForeground(new Color(69,69,69));
        question_Label.setFont(new Font(Font.SANS_SERIF,Font.BOLD,20));
        question_Label.setForeground(new Color(0,77,178));
        setTitle("PC Selector");
        ImageIcon img = new ImageIcon(getClass().getResource("icon.png"));
        setIconImage(img.getImage());
        setSize(900, 600);
        setResizable(true);
        drawFrame();
    }
    
    public void drawFrame()
    {
        try
        {
            bottomPanel.revalidate();
            bottomPanel.removeAll();
            optionPanel.revalidate();
            optionPanel.removeAll();
            final JButton previous = new JButton("Previous");
            final JButton next = new JButton("Next");
            previous.setBackground(new Color(0,114,198));
            next.setBackground(new Color(0,114,198));
            next.setSize(40, 40);
            previous.setSize(40, 40);
            next.setEnabled(false);
            bottomPanel.add(previous);
            bottomPanel.add(next);
            if(Questionaire.currentNo==1)
                previous.setVisible(false);
            previous.addActionListener(new ActionListener()
            {
                @Override
                public void actionPerformed(ActionEvent e)
                {
                    Questionaire.currentNo -= 1;
                    drawFrame();
                }
            });
            next.addActionListener(new ActionListener()
            {
                @Override
                public void actionPerformed(ActionEvent e)
                {
//                	JOptionPane.showMessageDialog(null, String.valueOf( minimumPrice ) );
//                	JOptionPane.showMessageDialog(null, String.valueOf( maximumPrice ) );
                    Questionaire.currentNo = Questionaire.currentNo + 1;
                    if(Questionaire.currentNo>questions.size())
                        new Suggestions(Questionaire.this,optionClicked,options,inferenceMap, minimumPrice, maximumPrice ).setVisible(true);
                    else
                        drawFrame();
                }
            });
            String question = Questionaire.currentNo + ". " + String.valueOf(questions.get(Questionaire.currentNo));
            question_Label.setText(question);
            List optionList = new ArrayList();
            optionList = options.get(currentNo);
            if(optionList!=null)
            {
                Iterator optionIterator = optionList.iterator();
                ButtonGroup optionGroup = new ButtonGroup();
                GridLayout gridLayout = new GridLayout(optionList.size(), 6);
                optionPanel.setLayout(gridLayout);
                Integer i = 1;
                while(optionIterator.hasNext())
                {
                    final Integer clicked = i;
                    String option = (String)optionIterator.next();
                    JRadioButton optionButton = new JRadioButton(option);
                    final JCheckBox checkBox = new JCheckBox(option);
                    optionGroup.add(optionButton);
                    Integer checkClicked = null;
                    if(Questionaire.currentNo!=4)
                    {
                        optionPanel.add(optionButton);
                        try
                        {
                            checkClicked = optionClicked.get(Questionaire.currentNo).get(0);
                        }
                        catch(Exception ex)
                        {
                            //System.out.println("Exception : "+ex.getLocalizedMessage());
                        }
                    }
                    else
                    {
                        optionPanel.add(checkBox);
                        checkBox.addActionListener(new ActionListener()
                        {
                            @Override
                            public void actionPerformed(ActionEvent e)
                            {
                                next.setEnabled(true);
                                List list = optionClicked.get(4);
                                if(list==null)
                                    list = new ArrayList();
                                if(checkBox.isSelected())
                                    list.add(clicked);
                                else
                                   list.remove(clicked);
                                optionClicked.remove(4);
                                optionClicked.put(4, list);
                            }
                        });
                        List checkBoxList = new ArrayList();
                        checkBoxList = (List)optionClicked.get(4);
                        if(checkBoxList!=null)
                        {
                            next.setEnabled(true);
                            for(Object check : checkBoxList)
                            {
                                if(check!=null && check.equals(clicked))
                                {
                                    checkBox.setSelected(true);
                                }
                            }
                        }
                    }
                    JLabel dummy = new JLabel("");
                    if(Questionaire.currentNo==1)
                    {
                        switch(clicked)
                        {
                            case 1 :
                                final JTextField from = new JTextField("From",0);
                                from.addFocusListener(new FocusListener()
                                {
                                    @Override
                                    public void focusGained(FocusEvent e)
                                    {
                                        if(from.getText().equals("From"))
                                        {
                                            from.setText("");
                                        }
                                    }
                                    @Override
                                    public void focusLost(FocusEvent e)
                                    {
                                        if(from.getText().equals(""))
                                        {
                                            from.setText("From");
                                        }else{
                                        	minimumPrice = Integer.parseInt( from.getText() );
                                        }
                                    }
                                });
                                final JTextField to = new JTextField("To",0);
                                from.addKeyListener(this);
                                to.addKeyListener(this);
                                to.addFocusListener(new FocusListener()
                                {
                                    @Override
                                    public void focusGained(FocusEvent e)
                                    {
                                        if(to.getText().equals("To"))
                                        {
                                            to.setText("");
                                        }
                                    }
                                    @Override
                                    public void focusLost(FocusEvent e)
                                    {
                                        if(to.getText().equals(""))
                                        {
                                            to.setText("To");
                                        }else{
                                        	maximumPrice = Integer.parseInt( to.getText() );
                                        }
                                    }
                                });
                                optionPanel.add(from);
                                optionPanel.add(to);
                                break;
                            case 2 : 
                                final JTextField around = new JTextField("Around",0);
                                around.addKeyListener(this);
                                around.addFocusListener(new FocusListener()
                                {
                                    @Override
                                    public void focusGained(FocusEvent e)
                                    {
                                        if(around.getText().equals("Around"))
                                        {
                                            around.setText("");
                                        }
                                    }
                                    @Override
                                    public void focusLost(FocusEvent e)
                                    {
                                        if(around.getText().equals(""))
                                        {
                                            around.setText("Around");
                                        } else{
                                        	minimumPrice = Integer.parseInt( around.getText() )-100;
                                        	maximumPrice = Integer.parseInt( around.getText() )+100;
                                        }
                                    }
                                });
                                optionPanel.add(around);
                                optionPanel.add(dummy);
                                break;
                            case 3 :
                                final JTextField minimum = new JTextField("Minimum",0);
                                final JTextField maximum = new JTextField("Maximum",0);
                                minimum.addKeyListener(this);
                                maximum.addKeyListener(this);
                                minimum.addFocusListener(new FocusListener()
                                {
                                    @Override
                                    public void focusGained(FocusEvent e)
                                    {
                                        if(minimum.getText().equals("Minimum"))
                                        {
                                            minimum.setText("");
                                        }
                                    }
                                    @Override
                                    public void focusLost(FocusEvent e)
                                    {
                                        if(minimum.getText().equals(""))
                                        {
                                            minimum.setText("Minimum");
                                        }else{
                                        	minimumPrice = Integer.parseInt( minimum.getText() );
                                        }
                                    }
                                });
                                maximum.addFocusListener(new FocusListener()
                                {
                                    @Override
                                    public void focusGained(FocusEvent e)
                                    {
                                        if(maximum.getText().equals("Maximum"))
                                        {
                                            maximum.setText("");
                                        }
                                    }
                                    @Override
                                    public void focusLost(FocusEvent e)
                                    {
                                        if(maximum.getText().equals(""))
                                        {
                                            maximum.setText("Maximum");
                                        }else{
                                         	maximumPrice = Integer.parseInt( maximum.getText() );
                                        
                                        }
                                    }
                                });
                                optionPanel.add(minimum);
                                optionPanel.add(maximum);
                                break;
                            case 4 : 
                                final JTextField maximum1 = new JTextField("Below",0);
                                maximum1.addKeyListener(this);
                                maximum1.addFocusListener(new FocusListener()
                                {
                                    @Override
                                    public void focusGained(FocusEvent e)
                                    {
                                        if(maximum1.getText().equals("Below"))
                                        {
                                            maximum1.setText("");
                                          
                                        }
                                    }
                                    @Override
                                    public void focusLost(FocusEvent e)
                                    {
                                        if(maximum1.getText().equals(""))
                                        {
                                            maximum1.setText("Below");
                                        }else{
                                        	minimumPrice = 0;
                                        	maximumPrice = Integer.parseInt( maximum1.getText() ); 
                                        }
                                    }
                                });
                                optionPanel.add(maximum1);
                                optionPanel.add(dummy);
                                break;
                        }
                    }
                    else
                    {
                        optionPanel.add(dummy);
                        optionPanel.add(dummy);
                    }
                    if(checkClicked!=null && checkClicked.equals(clicked))
                    {
                        next.setEnabled(true);
                        optionButton.setSelected(true);
                        optionButton.setForeground(new Color(0,78,160));
                        optionButton.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 14));
                    }
                    optionButton.addActionListener(new ActionListener()
                    {
                        @Override
                        public void actionPerformed(ActionEvent e)
                        {
                            List list = new ArrayList();
                            next.setEnabled(true);
                            if(Questionaire.currentNo>1)
                            {
                                previous.setVisible(true);
                            }
                            if(Questionaire.currentNo<questions.size())
                            {
                                optionClicked.remove(Questionaire.currentNo);
                                list.add(clicked);
                                optionClicked.put(Questionaire.currentNo, list);
                            }
                            else if(Questionaire.currentNo==4)
                            {
                                
                            }
                            else if(Questionaire.currentNo==questions.size())
                            {
                                next.setText("Done");
                                optionClicked.remove(Questionaire.currentNo);
                                list.add(clicked);
                                optionClicked.put(Questionaire.currentNo, list);
                                Questionaire.currentNo++;
                                /*mainPanel.setVisible(false);
                                startPanel.setVisible(false);
                                resultPanel.setVisible(true);
                                GridLayout resultLayout = new GridLayout(9, 2);
                                suggestionPanel.setLayout(resultLayout);
                                suggestionPanel.setBackground(Color.WHITE);
                                ArrayList<Label> labelList = processAnswer.returnLabels(optionClicked, inferenceMap);
                                try
                                {
                                    processManager = new ProcessManager();
                                    Collection<Laptop> suggestions = processManager.process(labelList);
                                    for(Iterator suggestionIterator = suggestions.iterator();suggestionIterator.hasNext();)
                                    {
                                        Laptop laptop = (Laptop)suggestionIterator.next();

                                        JLabel brandLabel = new JLabel("Brand :");
                                        brandLabel.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,16));
                                        JLabel nameLabel = new JLabel("Model Name :");
                                        nameLabel.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,16));
                                        JLabel cpuLabel = new JLabel("CPU");
                                        cpuLabel.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,16));
                                        JLabel ramLabel = new JLabel("RAM");
                                        ramLabel.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,16));
                                        JLabel gpuLabel = new JLabel("GPU");
                                        gpuLabel.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,16));
                                        JLabel graphicsmemoryLabel = new JLabel("Graphics Memory");
                                        graphicsmemoryLabel.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,16));
                                        JLabel hardiskmemoryLabel = new JLabel("Hard disk");
                                        hardiskmemoryLabel.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,16));
                                        JLabel screensizeLabel = new JLabel("Screen size");
                                        screensizeLabel.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,16));
                                        JLabel priceLabel = new JLabel("Price");
                                        priceLabel.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,16));

                                        JLabel brand = new JLabel(": "+laptop.getBrand());
                                        brand.setFont(new Font(Font.SANS_SERIF,Font.BOLD,16));
                                        JLabel name = new JLabel(": "+laptop.getName());
                                        name.setFont(new Font(Font.SANS_SERIF,Font.BOLD,16));
                                        JLabel cpu = new JLabel(": "+laptop.getCPU());
                                        cpu.setFont(new Font(Font.SANS_SERIF,Font.BOLD,16));
                                        JLabel ram = new JLabel(": "+laptop.getRAM());
                                        ram.setFont(new Font(Font.SANS_SERIF,Font.BOLD,16));
                                        JLabel gpu = new JLabel(": "+laptop.getGPU());
                                        gpu.setFont(new Font(Font.SANS_SERIF,Font.BOLD,16));
                                        JLabel graphicsmemory = new JLabel(": "+laptop.getGraphicalMemory());
                                        graphicsmemory.setFont(new Font(Font.SANS_SERIF,Font.BOLD,16));
                                        JLabel hardiskmemory = new JLabel(": "+laptop.getHDDSize());
                                        hardiskmemory.setFont(new Font(Font.SANS_SERIF,Font.BOLD,16));
                                        JLabel screensize = new JLabel(": "+laptop.getScreenSize());
                                        screensize.setFont(new Font(Font.SANS_SERIF,Font.BOLD,16));
                                        JLabel price = new JLabel(": "+laptop.getPrice());
                                        price.setFont(new Font(Font.SANS_SERIF,Font.BOLD,16));
                                        suggestionPanel.add(brandLabel);
                                        suggestionPanel.add(brand);
                                        suggestionPanel.add(nameLabel);
                                        suggestionPanel.add(name);
                                        suggestionPanel.add(cpuLabel);
                                        suggestionPanel.add(cpu);
                                        suggestionPanel.add(ramLabel);
                                        suggestionPanel.add(ram);
                                        suggestionPanel.add(gpuLabel);
                                        suggestionPanel.add(gpu);
                                        suggestionPanel.add(graphicsmemoryLabel);
                                        suggestionPanel.add(graphicsmemory);
                                        suggestionPanel.add(hardiskmemoryLabel);
                                        suggestionPanel.add(hardiskmemory);
                                        suggestionPanel.add(screensizeLabel);
                                        suggestionPanel.add(screensize);
                                        suggestionPanel.add(priceLabel);
                                        suggestionPanel.add(price);
                                    }
                                    processAnswer.displayRules(optionClicked,inferenceMap,rulesPanel);
                                } 
                                catch (Exception ex)
                                {
                                    Logger.getLogger(Questionaire.class.getName()).log(Level.SEVERE, null, ex);
                                }*/
                            }
                        }
                    });
                    i++;
                }
            }
            
            /*for(Integer j=1;j<=questions.size();++j)
            {
                final JLabel slNoLabel = new JLabel(""+j);
                slNoLabel.setName(""+j);
                Font font = null;
                font = new Font(Font.SANS_SERIF, Font.PLAIN, 12);
                if(j.equals(Questionaire.currentNo))
                {
                    font = new Font(Font.SANS_SERIF, Font.BOLD, 18);
                    slNoLabel.setForeground(Color.RED);
                }
                slNoLabel.setFont(font);
                bottomPanel.add(slNoLabel);
                slNoLabel.addMouseListener(new MouseListener()
                {
                    @Override
                    public void mouseClicked(MouseEvent e)
                    {
                        String name = e.getComponent().getName();
                        Integer checkClicked = optionClicked.get(Integer.parseInt(name));
                        if(Questionaire.currentNo<=questions.size())
                        {
                            if(checkClicked!=null)
                            {
                                Questionaire.currentNo = Integer.parseInt(slNoLabel.getText());
                                drawFrame();
                            }
                        }
                    }

                    @Override
                    public void mousePressed(MouseEvent e)
                    {
                        Integer checkClicked = optionClicked.get(Questionaire.currentNo);
                        if(Questionaire.currentNo<=questions.size())
                        {
                            if(checkClicked!=null)
                            {
                                Questionaire.currentNo = Integer.parseInt(slNoLabel.getText());
                                drawFrame();
                            }
                        }
                    }
                    @Override
                    public void mouseReleased(MouseEvent e)
                    {}
                    @Override
                    public void mouseEntered(MouseEvent e)
                    {}
                    @Override
                    public void mouseExited(MouseEvent e)
                    {}
                });
            }*/
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        
    }
    
    /**
     * Static block that initialises the questions and options for each questions Currently its given statically
     */
    static
    {
        /*Initialising the question list*/
        questions.put(1, "Which price do you prefer?");
        questions.put(2, "How portable do you need your laptop to be?");
        questions.put(3, "Which job will you use laptop in work?");
        questions.put(4, "Which job will you use laptop in entertainment?");
        questions.put(5, "Do you play games on laptop?");
        questions.put(6, "Do you view or edit movies and photos on your laptop?");
        
        /*Initialising the options for each question*/
        List optionsList = new ArrayList();
        optionsList.add("Price From ");
        optionsList.add("Around ");
        optionsList.add("From ");
        optionsList.add("Below ");
        optionsList.add("Any laptops which reach other requirements.");
        options.put(1, optionsList);
        
        optionsList = new ArrayList();
        optionsList.add("I’ll mostly use it at one fixed place. ");
        optionsList.add("I’ll sometimes take it with me. [portable]");//portable
        optionsList.add("I’m always at the go, it need to be super-portable. [ultraportable]");//ultraportable
        options.put(2, optionsList);
        
        optionsList = new ArrayList();
        optionsList.add("Not really. I mostly use laptop for entertainment.");
        optionsList.add("I will use laptop on daily job such as Word, Excel or collect informations from Internet.");
        optionsList.add("My work requires a PC that can run heavy-duty programs like Photoshop, QuickBooks, or AutoCAD.[Good Processing Capacity] ");//good processing capacity
        options.put(3, optionsList);
        
        optionsList = new ArrayList();
        optionsList.add("Watch movies from Internet.");
        optionsList.add("Play games");
        optionsList.add("Enjoy music[ Tune Recommendation ]");
        optionsList.add("Watch movies from CD-ROM[ CD-ROM ]");
        options.put(4, optionsList);
        
        optionsList = new ArrayList();
        optionsList.add("No, I don’t really play games ");
        optionsList.add("Sometimes I play casual games like Angry Birds, Fruit Ninja and Bejewele ");
        optionsList.add("I love games, especially someone like Call of Duty.[Detailed Games]");//detailed games
        options.put(5, optionsList);
        
        optionsList = new ArrayList();
        optionsList.add("I sometimes watch movies on Youtube and look at photos.");
        optionsList.add("I have a large collection of movies and photos, I view them each week. [Large collection of movies and photos]");//large collection of movies and photos
        optionsList.add("I watch HD movies and edit movies and photos by professional software.[professional editor]");//professional editor
        options.put(6, optionsList);
        
        Map inference = new LinkedHashMap();
        inference.put(2,"portable");
        inference.put(3,"ultraportable");
        inferenceMap.put(2, inference);
        inference = new LinkedHashMap();
        inference.put(3,"good processing capacity");
        inferenceMap.put(3, inference);
        inference = new LinkedHashMap();
        inference.put(3,"detailed games");
        inferenceMap.put(5, inference);
        inference = new LinkedHashMap();
        inference.put(2,"large collection of movies and photos");
        inference.put(3,"professional editor");
        inferenceMap.put(6, inference);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        question_Label = new javax.swing.JLabel();
        optionPanel = new javax.swing.JPanel();
        bottomPanel = new javax.swing.JPanel();
        startPanel = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        question_Label1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        resultPanel = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        suggestionPanel = new javax.swing.JPanel();
        rulesPanel = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(255, 255, 255));

        jLabel1.setText("Find your new PC");

        question_Label.setText("Which price do you prefer?");

        javax.swing.GroupLayout optionPanelLayout = new javax.swing.GroupLayout(optionPanel);
        optionPanel.setLayout(optionPanelLayout);
        optionPanelLayout.setHorizontalGroup(
            optionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 245, Short.MAX_VALUE)
        );
        optionPanelLayout.setVerticalGroup(
            optionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        bottomPanel.setLayout(new java.awt.GridLayout(1, 1));

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(58, 58, 58)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(question_Label, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(optionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(bottomPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addComponent(jLabel1)
                .addGap(54, 54, 54)
                .addComponent(question_Label)
                .addGap(37, 37, 37)
                .addComponent(optionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 53, Short.MAX_VALUE)
                .addComponent(bottomPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        question_Label.getAccessibleContext().setAccessibleName("question_Label");

        jLabel2.setText("Find your new PC");

        question_Label1.setText("Answer a few questions to find the right PC or tablet for you.");

        jButton1.setText("Get started");

        javax.swing.GroupLayout startPanelLayout = new javax.swing.GroupLayout(startPanel);
        startPanel.setLayout(startPanelLayout);
        startPanelLayout.setHorizontalGroup(
            startPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(startPanelLayout.createSequentialGroup()
                .addGap(58, 58, 58)
                .addGroup(startPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(startPanelLayout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(question_Label1, javax.swing.GroupLayout.DEFAULT_SIZE, 395, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        startPanelLayout.setVerticalGroup(
            startPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(startPanelLayout.createSequentialGroup()
                .addGap(48, 48, 48)
                .addComponent(jLabel2)
                .addGap(25, 25, 25)
                .addComponent(question_Label1)
                .addGap(28, 28, 28)
                .addComponent(jButton1)
                .addContainerGap(33, Short.MAX_VALUE))
        );

        jLabel3.setText("We recommend:");

        jButton2.setText("Start over");

        jButton3.setText("Display Rules");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setLayout(new java.awt.GridLayout(1, 2, 40, 0));

        suggestionPanel.setBackground(new java.awt.Color(255, 255, 255));
        suggestionPanel.setLayout(new java.awt.GridLayout(1, 4));
        jPanel1.add(suggestionPanel);

        rulesPanel.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout rulesPanelLayout = new javax.swing.GroupLayout(rulesPanel);
        rulesPanel.setLayout(rulesPanelLayout);
        rulesPanelLayout.setHorizontalGroup(
            rulesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 201, Short.MAX_VALUE)
        );
        rulesPanelLayout.setVerticalGroup(
            rulesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jPanel1.add(rulesPanel);

        javax.swing.GroupLayout resultPanelLayout = new javax.swing.GroupLayout(resultPanel);
        resultPanel.setLayout(resultPanelLayout);
        resultPanelLayout.setHorizontalGroup(
            resultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(resultPanelLayout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(resultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(resultPanelLayout.createSequentialGroup()
                        .addGroup(resultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(resultPanelLayout.createSequentialGroup()
                                .addComponent(jButton2)
                                .addGap(18, 18, 18)
                                .addComponent(jButton3)
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap())))
        );
        resultPanelLayout.setVerticalGroup(
            resultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(resultPanelLayout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addComponent(jLabel3)
                .addGap(28, 28, 28)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addGroup(resultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addContainerGap(179, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap(217, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(startPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap(87, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(resultPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap(54, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(resultPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(startPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap(16, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) throws Exception
    {
        try
        {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
            {
                if ("Nimbus".equals(info.getName()))
                {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        }
        catch (ClassNotFoundException ex) 
        {
            java.util.logging.Logger.getLogger(Questionaire.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (InstantiationException ex)
        {
            java.util.logging.Logger.getLogger(Questionaire.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (IllegalAccessException ex)
        {
            java.util.logging.Logger.getLogger(Questionaire.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (javax.swing.UnsupportedLookAndFeelException ex)
        {
            java.util.logging.Logger.getLogger(Questionaire.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                new Questionaire().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel bottomPanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JPanel optionPanel;
    private javax.swing.JLabel question_Label;
    private javax.swing.JLabel question_Label1;
    private javax.swing.JPanel resultPanel;
    private javax.swing.JPanel rulesPanel;
    private javax.swing.JPanel startPanel;
    private javax.swing.JPanel suggestionPanel;
    // End of variables declaration//GEN-END:variables

    @Override
    public void keyTyped(KeyEvent e)
    {
        int key = (int)e.getKeyChar();
        char c = (char)34;
        if (!((key <= 57 && key >= 48) ||key==8))
            e.consume();
    }

    @Override
    public void keyPressed(KeyEvent e)
    {
        int key = (int)e.getKeyChar();
        char c = (char)34;
        if (!((key <= 57 && key >= 48) ||key==8))
            e.consume();
    }

    @Override
    public void keyReleased(KeyEvent e)
    {
        
    }
    
    public void clearAll()
    {
        Questionaire.currentNo =1;
        Questionaire.questionClicked = 1;
        optionClicked.clear();
        resultPanel.setVisible(false);
        initComponents();
        init();
    }
}